import fetch from 'common/src/utils/fetch'
let apiPrefix = '/api/studentservice/';
// 获取异动管理列表
export function applyList(data = {}) {
    return fetch({
        url: apiPrefix + 'apply/applyList',
        method: 'post',
        data
    });
}

// 下载导入模板
export function downloadTemplate(data = {}) {
    let url = apiPrefix + 'apply/downloadTemplate';
    window.open(url);
}

// 导出异动申请列表
// export function downloadApplyList(data = {}) {
//     let params = getParams(data); 
//     let url = apiPrefix + 'apply/exportApplyXlsx';
//     params && (url += `?${params}`);
//     window.open(url);
// }

// 导出学籍异动申请表
// export function downloadStudentStatusList(data = {}) {
//     let params = getParams(data); 
//     let url = apiPrefix + 'apply/exportApplyDocxZip';
//     params && (url += `?${params}`);
//     window.open(url);
// }

function getParams(data = {}) {
    let keys = Object.keys(data).filter(item => data[item]);
    // let keys = Object.keys(data).map(item => {return item;});
    let params = keys.reduce((prev, curr, index) => {
        prev += curr + '=' + data[curr];
        if (index < keys.length - 1) {
            prev += '&';
        }
        return prev;
    }, '');
    return params;
}
/**
 * @param {*} api 导出类名/方法名
 * @param {*} params 导出需要的参数
 */
export function exportClass(api, params = {}) {
    let url = apiPrefix + api;
    let string = "";
    for (var key in params) {
        string += `${key}=${params[key] ? params[key] : ""}&`
    }
    let restApi = `${url}?${string.substring(0, string.length - 1)}`;
    window.location.href = restApi;
}
/**
 * 撤销学籍异动信息
 * data {id :studentID }
 */
export function cancelApply(data) {

    return fetch({
        url: apiPrefix + 'apply/cancelApply ',
        method: 'post',
        data
    });

}
export function importApply(data) {
    return fetch({
        url: apiPrefix + 'apply/importApply',
        method: 'post',
        data
    });

}

// 获取异动到期名单列表
export function timeIsUpList(data = {}) {
    return fetch({
        url: apiPrefix + 'apply/timeIsUpList',
        method: 'post',
        data
    });
}